#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int tmp[] = { 0 };
void mergesort(int arr[], int l, int r)
{
	if (l >= r)	return;
	int mid = l + r >> 1;
	mergesort(arr, l, mid), mergesort(arr, mid + 1, r);

	int k = 0, i = l, j = mid + 1;
	while (l <= mid && j <= r)
	{
		if (arr[i] <= arr[j]) tmp[k++] = arr[i++];
		else tmp[k++] = arr[j++];
	}
	while (i <= mid) tmp[k++] = arr[i++];
	while (j <= r) tmp[k++] = arr[j++];
	for (int i = l, j = 0; i <= r; i++, j++)
	{
		arr[i]=tmp[j];
	}
}